package com.xq.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.xq.mapper.UserMapper;
import com.xq.pojo.User;
import com.xq.service.UserService;

/**
 * @author xq
 * @version 1.0
 * @date 2021/4/28 19:53
 * @description
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    @CacheEvict(cacheNames = "user", key = "#userId")
    public int deleteByPrimaryKey(Integer userId) {
        return userMapper.deleteByPrimaryKey(userId);
    }

    @Override
    @CachePut(cacheNames = "user", key = "#record.userId")
    public User insert(User record) {
        userMapper.insert(record);
        return record;
    }

    @Override
    @Cacheable(cacheNames = "user", key = "#userId")
    public User selectByPrimaryKey(Integer userId) {
        return userMapper.selectByPrimaryKey(userId);
    }

    @Override
    @CachePut(cacheNames = "user", key = "#record.userId")
    public User updateByPrimaryKey(User record) {
        this.userMapper.updateByPrimaryKey(record);
        return record;
    }

}
